package cn.cheegon.blog.controller;

import cn.cheegon.blog.common.api.CommonResult;
import cn.cheegon.blog.entity.req.EditMessageReq;
import cn.cheegon.blog.entity.req.AddMessageReq;
import cn.cheegon.blog.model.CmsMessage;
import cn.cheegon.blog.service.CmsMessageService;
import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 留言表 前端控制器
 * </p>
 *
 * @author cheegon
 * @since 2024-06-21
 */
@RestController
@RequestMapping("/message/*")
public class CmsMessageController {
    @Autowired
    private CmsMessageService cmsMessageService;

    @PostMapping("addMessage")
    public CommonResult addMessage(@RequestBody AddMessageReq req) {
        cmsMessageService.add(BeanUtil.toBean(req, CmsMessage.class));
        return CommonResult.success();
    }

    @PostMapping("editMessage")
    public CommonResult editMessage(@RequestBody EditMessageReq req) {
        cmsMessageService.editSelf(BeanUtil.toBean(req, CmsMessage.class));
        return CommonResult.success();
    }

    @GetMapping("delMessage/{id}")
    public CommonResult delMessage(@PathVariable Long id) {
        cmsMessageService.delSelf(id);
        return CommonResult.success();
    }
}
